package com.ask.forMe.controller.business;

import com.ask.forMe.model.dto.GroupByDTO;
import com.ask.forMe.model.entity.GroupBuyActivity;
import com.ask.forMe.model.entity.Result;
import com.ask.forMe.service.GroupBuyActivityService;
import com.ask.forMe.service.GroupBuyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/groupBuy")
@Tag(name = "拼团接口")
public class GroupBuyController {
    @Autowired
    private GroupBuyActivityService groupBuyActivityService;

    @Autowired
    private GroupBuyService groupBuyService;

    @PostMapping("/publish")
    @Operation(summary = "商家发布拼团活动")
    public Result publish(@RequestBody GroupBuyActivity activity) {
        groupBuyActivityService.publishGroupBuyActivity(activity);
        return Result.success();
    }


    /**
     * 用户发起拼单
     *
     * @param groupByDTO
     * @return
     */
    @PostMapping("/make")
    public Result createTeam(@RequestBody GroupByDTO groupByDTO) {
        groupBuyService.createTeam(groupByDTO);
        return null;
    }
    
    /**
     * 用户加入拼团
     *
     * @param groupByDTO
     * @return
     */
    @PostMapping("/join")
    public Result joinTeam(@RequestBody GroupByDTO groupByDTO) {
        boolean success = groupBuyService.joinTeam(groupByDTO);
        return success ? Result.success("拼团成功！") : Result.fail("拼团失败！");
    }


}
